package com.example.lenovo.test1;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;

import java.util.ArrayList;

public class Main5Activity extends AppCompatActivity implements  androidx.appcompat.app.ActionBar.TabListener  {

    private ArrayList<Fragment> mListFragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main5);
        mListFragments = new ArrayList<Fragment>();
        mListFragments.add(new FragmentViewPager1());
        mListFragments.add(new FragmentViewPager2());
        mListFragments.add(new FragmentViewPager3());
        initView();

    }
    protected void initView() {
        //android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        actionBar.newTab().setText("Tabl1").setTabListener(this);

        androidx.appcompat.app.ActionBar.Tab tab = actionBar.newTab().setText("Tabl1").setTabListener(this);
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText("Tabl2").setTabListener(this);
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText("Tabl3").setTabListener(this);
        actionBar.addTab(tab);

    }

    @Override
    public void onTabSelected(androidx.appcompat.app.ActionBar.Tab tab, androidx.fragment.app.FragmentTransaction ft) {
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content,mListFragments.get(tab.getPosition())).commit();
    }

    @Override
    public void onTabUnselected(androidx.appcompat.app.ActionBar.Tab tab, androidx.fragment.app.FragmentTransaction ft) {

    }

    @Override
    public void onTabReselected(androidx.appcompat.app.ActionBar.Tab tab, androidx.fragment.app.FragmentTransaction ft) {

    }
}
